//
// Created by pc on 2018/3/15.
//
#include "com_zq_versionupdate_PatchUtil.h"
#include "bsdiff.c"
#include "bspatch.c"
/*
 * Class:     com_zq_versionupdate_PatchUtil
 * Method:    makePatchFile
 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
 */
JNIEXPORT jint JNICALL Java_com_zq_versionupdate_PatchUtil_makePatchFile
        (JNIEnv *env, jobject obj, jstring oldFilePath, jstring newFilePath,
         jstring patchFilePath) {

    const char *old_file_path = (*env)->GetStringUTFChars(env, oldFilePath, 0);
    const char *new_file_path = (*env)->GetStringUTFChars(env, newFilePath, 0);
    const char *patch_file_path = (*env)->GetStringUTFChars(env, patchFilePath, 0);

    int result = make_patch_file(old_file_path, new_file_path, patch_file_path);

    (*env)->ReleaseStringUTFChars(env, oldFilePath, old_file_path);
    (*env)->ReleaseStringUTFChars(env, newFilePath, new_file_path);
    (*env)->ReleaseStringUTFChars(env, patchFilePath, patch_file_path);
    return result;
}

/*
 * Class:     com_zq_versionupdate_PatchUtil
 * Method:    mergePatchFile
 * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
 */
JNIEXPORT jint JNICALL Java_com_zq_versionupdate_PatchUtil_mergePatchFile
        (JNIEnv *env, jobject obj, jstring oldFilePath, jstring patchFilePath,
         jstring newFilePath) {

    const char *old_file_path = (*env)->GetStringUTFChars(env, oldFilePath, 0);
    const char *new_file_path = (*env)->GetStringUTFChars(env, newFilePath, 0);
    const char *patch_file_path = (*env)->GetStringUTFChars(env, patchFilePath, 0);

    int result = mergePatchFile(old_file_path, patch_file_path, new_file_path);

    (*env)->ReleaseStringUTFChars(env, oldFilePath, old_file_path);
    (*env)->ReleaseStringUTFChars(env, newFilePath, new_file_path);
    (*env)->ReleaseStringUTFChars(env, patchFilePath, patch_file_path);
    return result;
}
